﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BasePanel : MonoBehaviour
{
    private CanvasGroup canvasGroup;
    /// <summary>
    /// 进入
    /// </summary>
    public virtual void OnEnter()
    {
        ShowPanel(true);
    }
    /// <summary>
    /// 暂停
    /// </summary>
    public virtual void OnPause()
    {
        PausePanel(true);
    }
    /// <summary>
    /// 继续
    /// </summary>
    public virtual void OnResume()
    {
        PausePanel(false);
    }
    /// <summary>
    /// 退出
    /// </summary>
    public virtual void OnExit()
    {
        ShowPanel(false);
    }
    protected void ShowPanel(bool isShow)
    {
        if (canvasGroup == null)
            canvasGroup = GetComponent<CanvasGroup>();
        canvasGroup.alpha = isShow? 1 : 0;
        canvasGroup.blocksRaycasts = isShow;
    }
    protected void PausePanel(bool isPause)
    {
        if (canvasGroup == null)
            canvasGroup = GetComponent<CanvasGroup>();
        canvasGroup.blocksRaycasts = !isPause;
    }
}
